package erQiao.yfl.app.service;

import erQiao.yfl.app.dao.entity.Circle;
import erQiao.yfl.app.dao.entity.Topic;
import erQiao.yfl.app.dao.mapper.TopicMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 *  话题
 */
@Service
public class TopicService {
    @Resource
    private TopicMapper topicMapper;

    public int deleteByPrimaryKey(Integer id){
        return topicMapper.deleteByPrimaryKey(id);
    }

    public int insert(Topic record){
        return topicMapper.insert(record);
    }


    public int updateByPrimaryKey(Topic record){
        return topicMapper.updateByPrimaryKey(record);
    }


    /**
     *  根据用户 关注的圈子
     * @param userid
     * @return
     */
    public List<Topic> selectByUserId(int userid){
        return topicMapper.selectMyTopicByUserId(userid);
    }

    /**
     *
     * @param record
     * @return
     */
    public int updteUpvote(int id){
        Topic topic= topicMapper.selectByPrimaryKey(id);
        Topic _topic = new Topic();
        _topic.setId(id);
        _topic.setUpvotenum(topic.getUpvotenum()+1);
        return topicMapper.updateByPrimaryKey(_topic);
    }





}
